/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iss.examsys.view;

import com.iss.examsys.common.EmsConstants;
import com.iss.examsys.ejb.QuestionBean;
import com.iss.examsys.entity.AnswerChoice;
import com.iss.examsys.entity.Module;
import com.iss.examsys.entity.Question;
import com.iss.examsys.entity.QuestionPart;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Named;

/**
 *
 * @author Quek Ting Hong
 */
@RequestScoped
@Named
public class QuestionView {
    @EJB QuestionBean questionBean;
    
    private Long questionId;
    private Question selectedQuestion = new Question();
    private List<Question> selectedQuestions;
    
    private Question newQuestion = new Question();
    private List<Question> allQuestion;

    public QuestionBean getQuestionBean() {
        return questionBean;
    }

    public void setQuestionBean(QuestionBean questionBean) {
        this.questionBean = questionBean;
    }

    public Long getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Long questionId) {
        this.questionId = questionId;
    }

    public Question getSelectedQuestion() {
        return selectedQuestion;
    }

    public void setSelectedQuestion(Question selectedQuestion) {
        this.selectedQuestion = selectedQuestion;
    }

    public List<Question> getSelectedQuestions() {
        return selectedQuestions;
    }

    public void setSelectedQuestions(List<Question> selectedQuestions) {
        this.selectedQuestions = selectedQuestions;
    }

    public Question getNewQuestion() {
        return newQuestion;
    }

    public void setNewQuestion(Question newQuestion) {
        this.newQuestion = newQuestion;
    }

    public List<Question> getAllQuestion() {
        return allQuestion;
    }

    public void setAllQuestion(List<Question> allQuestion) {
        this.allQuestion = allQuestion;
    }
    
    public void createQuestion(){
        //TODO testing only
        newQuestion.setMark(10);
        newQuestion.setText("DIfficult Question");
        
        Module m = new Module();
        m.setId(1L);
        newQuestion.setModuleId(m);
        
        QuestionPart qPart1 = new QuestionPart();
        qPart1.setText("Question 1");
        
        qPart1.setQuestionType(EmsConstants.QUESTION_TYPE_ESSAY);
        qPart1.setQuestionId(newQuestion);
        
        QuestionPart qPart2 = new QuestionPart();
        qPart2.setText("Question 1");        
        qPart2.setQuestionType(EmsConstants.QUESTION_TYPE_MULTI_CHOICE_MULTI_ANS);
        qPart2.setQuestionId(newQuestion);
        
        AnswerChoice ac = new AnswerChoice();
        ac.setText("asdasd");
        ac.setQuestionPartId(qPart2);
        List<AnswerChoice> acList = new ArrayList<>();
        
        acList.add(ac);
        
        qPart2.setAnswerChoiceList(acList);
        
        List<QuestionPart> qpList = new ArrayList();
        qpList.add(qPart1);
        qpList.add(qPart2);
                
        newQuestion.setQuestionPartList(qpList);
        
        questionBean.createModule(newQuestion);
        
    }
    
     public Question getQuestion(java.lang.Long id) {
        return questionBean.find(id);
    }
       
    
}
